/*把file1中的内容复制到file2中*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>

//./10-fseek filename  file1 file2 file3
// arg[0] argv[1] argv[2] argv[3]
int main(int argc, char const *argv[])
{
    FILE *fp1, *fp2, *fp3;
    if (argc != 4)
    {
        fprintf(stderr, "运行程序时，请带入参数 ./10-fseek file1 file2 file3 \n");
        exit(-1);
    }
    //
    fp1 = fopen(argv[1], "r");
    if (fp1 == NULL)
    {
        perror("fopen");
        exit(-1);
    }
    fp2 = fopen(argv[2], "r");
    if (fp2 == NULL)
    {
        perror("fopen");
        exit(-1);
    }
    fp3 = fopen(argv[3], "w");
    if (fp3 == NULL)
    {
        perror("fopen");
        exit(-1);
    }

    int ch = 0;
    while ((ch = fgetc(fp1)) != EOF)
    {
        fputc(ch, fp3);
    }

    while ((ch = fgetc(fp2)) != EOF)
    {
        fputc(ch, fp3);
    }

    fclose(fp1);
    fclose(fp2);
    fclose(fp3);

    return 0;
}
